package de.koller.worlders.engine;

import de.koller.worlders.WSea;

public class SyncClear extends WSea {
	
	private int nextClear = 5000;
	private boolean reloadAll = false;
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		if( reloadAll )
			reloadNow();
		if( wroot.getTime() > nextClear )
			clearSync();
	}
	
	public void clearSync() {
		wroot.getTileMap().tileHolder.timeoutTile();
		
		nextClear = (int)wroot.getTime() + 5000;
	}
	
	public void reloadAll() {
		reloadAll = true;
	}
	
	synchronized private void reloadNow() {
		if( wroot.getTileMap().tileHolder.isLocked() )
			return;
		
		wroot.getTileMap().tileHolder.clearAllTiles();
		
		reloadAll = false;
	}
	
}
